package com.yfp.machine.controller;

import com.yfp.common.core.domain.R;
import com.yfp.common.core.web.controller.BaseController;
import com.yfp.common.core.web.page.TableDataInfo;
import com.yfp.common.log.annotation.Log;
import com.yfp.common.log.enums.BusinessType;
import com.yfp.machine.domain.TagMachine;
import com.yfp.machine.domain.vo.TagMachineVo;
import com.yfp.machine.service.TagMachineService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;


/**
 * (TagMachine)表控制层
 *
 *
 * @since 2023-12-14 21:54:28
 */
@Tag(name = "标签管理")
@RestController
@RequestMapping("tagMachine")
public class TagMachineController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private TagMachineService tagMachineService;

    /**
     * 分页查询
     *
     * @param tagMachine 筛选条件
     * @return 查询结果
     */
    @GetMapping
    @Operation(summary = "分页查询所有数据")
    public TableDataInfo queryByPage(TagMachine tagMachine,
                                     @Valid Integer pageNum,
                                     @Valid Integer pageSize) {
        return getDatableByStream(this.tagMachineService.queryAll(tagMachine), pageNum, pageSize);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @Operation(summary = "通过主键查询单条数据")
    @GetMapping("{id}")
    public R<TagMachine> queryById(@PathVariable("id") String id)
    {
        return R.ok(this.tagMachineService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param tagMachineVo 实体
     * @return 新增结果
     */
    @Operation(summary = "新增设备标签")
    @Log(title = "新增设备标签", businessType = BusinessType.INSERT)
    @PostMapping
    public R<TagMachine> add(@RequestBody @Valid TagMachineVo tagMachineVo)
    {
        return R.ok(this.tagMachineService.insertTagMachine(tagMachineVo));
    }


    /**
     * 禁用标签
     *
     * @param id id
     * @return 禁用标签
     */
    @Operation(summary = "禁用/启用标签")
    @GetMapping("disabled/{id}")
    @Log(title = "禁用标签", businessType = BusinessType.UPDATE)
    public R disabled(@PathVariable("id") String id)
    {
        return this.tagMachineService.disableTags(id);
    }

    /**
     * 编辑数据
     *
     * @param tagMachine 实体
     * @return 编辑结果
     */
    @Operation(summary = "修改设备标签")
    @Log(title = "修改设备标签", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<TagMachine> edit(@Valid @RequestBody TagMachine tagMachine)
    {
        return R.ok(this.tagMachineService.update(tagMachine));
    }


}

